using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing.Imaging;
using System.Web.UI.WebControls;

namespace Zoo
{
    public static class Utility
    {
        public static bool IsEmpty(string aString)
        {
            if (IsNull(aString))
                return true;

            return aString.Length < 1;
        }

        public static bool IsNull(object o)
        {
            return o == null;
        }

        public static string GetDateString(int day, int month, int year)
        {
            string dateString = day + "/" + month + "/" + year;
            return dateString;
        }

        public static byte[] Resize(byte[] rawPicture, int height, System.Drawing.Imaging.ImageFormat imageFormat)
        {
            MemoryStream output = new MemoryStream();
            System.Drawing.Image image;
            try
            {
                image = System.Drawing.Image.FromStream(new MemoryStream(rawPicture));
            }
            catch (ArgumentException)
            {
                throw new InvalidImageException();
            }
            image = resizeImageWithMaxHeight(image, height);
            image.Save(output, imageFormat);
            return output.ToArray();
        }

        private static System.Drawing.Image resizeImageWithMaxHeight(System.Drawing.Image image, int newHeight)
        {
            float ratio = ((float)image.Width) / ((float)image.Height);
            int newWidth = Convert.ToInt32(newHeight * ratio); ;
            System.Drawing.Image myThumbnail = image.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
            return myThumbnail;
        }

        public static string[] ToStringArray(ListItemCollection col)
        {
            string[] returnVal = new string[col.Count];
            for (int i = 0; i < col.Count; i++)
            {
                returnVal[i] = col[i].Value;
            }

            return returnVal;
        }



        
    }
}
